﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Apache.NMS.Util;
using Apache.NMS.ActiveMQ.Commands;
using System.Collections;
using System.IO;

namespace Transport
{
    class Program
    {
        private static IConnection _connection;
        private static ISession _session;
        private static IDestination _destination;
        private static IQueueBrowser _browser;

        public const String QUEUE_ADVISORY_DESTINATION = "parameters";

        static void Main(string[] args)
        {
            IConnectionFactory factory = new ConnectionFactory();
            connection = factory.CreateConnection();
            connection.Start();
            session = connection.CreateSession();
            IDestination destination = session.GetQueue(QUEUE_ADVISORY_DESTINATION);
            IQueueBrowser browser = session.CreateBrowser((IQueue)_destination);
            IEnumerator enumeration = browser.GetEnumerator();
            ArrayList values = new ArrayList();
            Logger log = Logger.getInstance();
            while (enumeration.MoveNext())
            {
                IMessage message = (IMessage)enumeration.Current;
                values = (ArrayList)message.Properties.Values;
                
                log.WriteToFile(values[0].ToString() + "#" + values[values.Count - (values.Count -3)].ToString());
            }
            log.Close();
            Console.ReadKey(true);
        }
    }
}
